using UnityEngine;
using System.Collections;

public class LevelGUI : MonoBehaviour 
{
	public static int score = 0;
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}
	void OnGUI () 
	{
		GUI.Box(new Rect(700,600,100,30), score.ToString());	
	}
	
	public void addScore(string name, int score)
	{
		int newScore, oldScore;
		string newName,oldName;
		
		newName = name;
		newScore = score;
		
		for(int i = 0;i < 3;i++)
		{
			if(PlayerPrefs.HasKey(i + "HScore"))
				{
					if(PlayerPrefs.GetInt(i + "HScore") < newScore)
						{
							// new score is higher than the stored score
							oldScore = PlayerPrefs.GetInt(i + "HScore");
							oldName = PlayerPrefs.GetString(i + "HScoreName");
							PlayerPrefs.SetInt(i + "HScore",newScore);
							PlayerPrefs.SetString(i + "HScoreName",newName);
							newScore = oldScore;
							newName = oldName;
						}
				}
			else
			{
				PlayerPrefs.SetInt(i+"HScore",newScore);
				PlayerPrefs.SetString(i+"HScoreName",newName);
				newScore = 0;
				newName = "";
			}
		}
	}
}
